/*
 *  fileIO.c
 *  oE6
 *
 *  Created by Tony Million on 12/12/2008.
 *  Copyright 2008 Tony Million. All rights reserved.
 *
 */

#include "fileIO.h"
#include <stdio.h>

static FILE * fp = 0;

int oEopen(char * filename)
{
	fp = fopen(filename, "rb");
	if(!fp)
		return 0;
	
	return 1;
}

int oEclose(void)
{
	if(fp)
	{
		fclose(fp);
		fp = 0;
	}
	
	return 0;
}

int oEread(void * toHere, unsigned long bytestoread)
{
	return fread(toHere, 1, bytestoread, fp);
}

int oErewind(long bytes)
{
	//printf("old offset = %d\r\n", ftell(fp));
	int ret = fseek(fp, -bytes, SEEK_CUR);
	//printf("new offset = %d\r\n", ftell(fp));
	return ret;
}


int oEsetpos(unsigned long bytesfrombeginning)
{
	int ret = fseek(fp, bytesfrombeginning, SEEK_SET);
	printf("new offset = %d\n", ftell(fp));
	return ret;
}

int oEEOF(void)
{
	return feof(fp);
}